/* 
    1. 配置公共的url
    2. 对请求和返回进行拦截
    3. 加遮罩
    https://mobile.ant.design/components/toast-cn/
*/
import axios from "axios";
import { Toast } from "antd-mobile";
import Loading from "../assets/images/loading.jpg"
const instance = axios.create({
  baseURL:process.env.REACT_APP_BASEURL,
});
/* 请求的拦截器 */
instance.interceptors.request.use(
  function (config) {
    // TODO 添加token 信息上去
    // console.log(config);
    Toast.show(<img style={{width:"100px",height:"100px"}} src={Loading}></img>, 0);
    return config;
  },
  function (error) {
    Toast.hide();
    return Promise.reject(error);
  }
);
/* 响应的拦截器 */
instance.interceptors.response.use(
  (response) => {
    Toast.hide();
    return response.data;
  },
  (error) => {
    Toast.hide();
    return Promise.reject(error);
  }
);
export default instance;
